package com.smt.modules.app.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.smt.common.utils.R;
import com.smt.modules.app.annotation.Login;
import com.smt.modules.app.annotation.LoginUser;
import com.smt.modules.bus.entity.GradeEntity;
import com.smt.modules.bus.entity.MemberUserEntity;
import com.smt.modules.bus.service.GradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 企业等级操作
 *
 * @author zhangyi
 * @date 2018/10/16 16:59
 */
@RestController
@RequestMapping("/app/level")
@Api(description = "用户等级操作(客户端接口)")
public class AppMemberLevelController {

    @Resource
    private GradeService gradeService;

    /**
     * 获取当前用户的企业等级
     *
     * @return
     */
    @Login
    @GetMapping("/getLevel")
    @ApiOperation(value = "获取当前用户的企业等级",httpMethod = "GET")
    public R getCurrentLevel(@LoginUser MemberUserEntity user){
        Long userId = user.getUserId();
        GradeEntity gradeEntity = gradeService.selectOne(new EntityWrapper<GradeEntity>()
                .eq("member_id", userId));
        Integer level = gradeEntity.getLevel();
        return R.ok().put(userId+"-level",level);
    }
}
